package richy.com.floatingball;

import android.accessibilityservice.AccessibilityService;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;

/**
 * Created by rentianxin on 17-10-16.
 */

public class FloatingBallService extends AccessibilityService {
    public static final String TAG = "FloatingBallService";
    public static final String TYPE = "type";
    public static final int TYPE_ADD = 1;
    public static final int TYPE_DEL = 2;
    private FloatingWindowManager mFloatingWindowManager;

    @Override
    public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) {

    }

    @Override
    public void onInterrupt() {

    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Bundle bundle = intent.getExtras();
        if (bundle != null) {
            final int type = bundle.getInt(TYPE, -1);
            Log.d(TAG, "type : " + type);
            if (type == TYPE_ADD) {
                mFloatingWindowManager.addBallToWindow(this);
            } else if (type == TYPE_DEL) {
                mFloatingWindowManager.removeBallFromWindow();
            }
        }
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mFloatingWindowManager = new FloatingWindowManager();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mFloatingWindowManager = null;
    }
}
